<?php
class Config {
    private static $config = array();
    /**
     * 类构造函数，静态类，禁止实例化
     */
    private function __construct() {}
    
    /**
     * 获取程序设置值
     *
     * @param String $key
     * @return mixed
     */
    public static function get($key) {
        $key = strtoupper($key);
        if (array_key_exists($key, self::$config)) {
            return self::$config[$key];
        }
        throw new Exception('键值错误，找不到键值为“' . $key . '”的设置');
    }
    
    /**
     * 修改程序设置值
     *
     * @param String $key
     * @param mixed $val
     */
    public static function set($key, $val) {
        $key = strtoupper($key);
        self::$config[$key] = $val;
    }
    
    /**
     * 加载系统设置
     */
    public static function loadConf() {
        $sysConfFile =  PUMP_DIR . '/Config.php';
        self::$config = require($sysConfFile);
        if (file_exists(APPCONF_FILE)) {
            $appConf = require(APPCONF_FILE);
            if (is_array($appConf)) {
                foreach ($appConf as $key=>$val) {
                    self::set($key, $val);
                }
            }
        }
    }

    public static function loadUserConf($confName) {
        $upperConfName = strtoupper($confName);
        if(isset(self::$config[$upperConfName])) 
            return self::$config[$upperConfName];
        $confFile = USER_CONF_DIR . '/' . $confName . '.conf.php';
        if (file_exists($confFile)) {
            $config = require_once($confFile);
            self::set($upperConfName, $config);
            return $config;
        }
    }
}
?>